package zucc.edu.repay.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import Bean.summary;
import Util.BaseException;
import Util.HibernateUtil;

public class SummaryDao{
	public void delSummary(summary summary) {
		// TODO �Զ����ɵķ������
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = s.beginTransaction();
		s.delete(summary);
		tx.commit();
		
	}
	
	public void addSummary(summary summary) {
		// TODO �Զ����ɵķ������
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = s.beginTransaction();
		s.save(summary);
		tx.commit();
				
	}
	
	public void updateSummary(summary summary) {
		// TODO �Զ����ɵķ������
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = s.beginTransaction();
		s.update(summary);
		tx.commit();
		
	}
	
	public summary searchSummary(String summaryid) throws BaseException{
		// TODO �Զ����ɵķ������
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = s.beginTransaction();
		String hql = "from summary where summaryid = '" + summaryid + "'";
		Query qry = s.createQuery(hql);
		Object summary = qry.uniqueResult();
		tx.commit();
		return (summary)summary;
	}
	
	public List<summary> serarchAllSummary(){//�������û�
		Session s = HibernateUtil.getSessionFactory().getCurrentSession(); 
		Transaction tx = s.beginTransaction();
        String hql = "from summary";  
        Query query = s.createQuery(hql);  
        List<summary> roles = query.list();  
        tx.commit();
        return roles; 
}
}
